package com.spider;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.spider.model.Lagou;
import com.spider.model.LagouInfo;
import com.spider.web.IndexController;
import com.spider.web.LagouController;

public class SpiderConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setError404View("/error/404.html");
		me.setError500View("/error/500.html");
		me.setBaseViewPath("/WEB-INF/jsp/");
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configHandler(Handlers me) {
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configPlugin(Plugins me) {
		super.loadPropertyFile("jdbc.txt");
		
		String url = super.getProperty("jdbcUrl");
		String username = super.getProperty("username");
		String password = super.getProperty("password");
		DruidPlugin dp = new DruidPlugin(url, username, password);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(dp);
		arp.setShowSql(true);
		arp.addMapping("lagou", Lagou.class);
		arp.addMapping("lagou_info", LagouInfo.class);
		me.add(arp);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/lagou", LagouController.class);
	}

}
